package com.ydd.controller.admin;

import com.alibaba.fastjson.JSON;
import com.ydd.dto.SysMenuAddDTO;
import com.ydd.dto.SysMenuDto;
import com.ydd.entity.SysMenu;
import com.ydd.result.Result;
import com.ydd.service.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/sys_menu")
public class SysMenuController {
    @Autowired
    private SysMenuService sysMenuService;



    //所有菜单
    @GetMapping("/allData")
    public Result findAll() {
        List<SysMenuDto> list =  sysMenuService.allData();
        return Result.success(list);
    }

    //菜单详情
    @GetMapping("/rowInfo")
    public Result details(Integer id) {
        SysMenu id1 = sysMenuService.getById(id);
        return  Result.success(id1);
    }

    //菜单修改
    @PostMapping("/update")
    public Result updateSysMenu(@RequestBody Map<String,Object> map) {
        String jsonString = JSON.toJSONString(map);
        SysMenu sysMenu = JSON.parseObject(jsonString,SysMenu.class);
        boolean b = sysMenuService.updateById(sysMenu);
        System.out.println(b);
        return Result.success();
    }
    //菜单删除
    @GetMapping("/del")
    public Result deleteMenu(Integer id){
        sysMenuService.deleteMenu(id);
        return Result.success();
    }


    //菜单添加
   /* @PostMapping("/add")
    public Result addSysMenu(@RequestBody Map<String,Object> map){
        String jsonString = JSON.toJSONString(map);
        SysMenu sysMenu = JSON.parseObject(jsonString, SysMenu.class);
        boolean save = sysMenuService.save(sysMenu);
        System.out.println(save);
        return Result.success();
    }*/

    //菜单添加
    @PostMapping("/add")
    public Result add(@RequestBody SysMenuAddDTO dto){
        sysMenuService.add(dto);
        return Result.success();
    }

}
